﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SpawnParticleEffect : LogicalEffectBase
{
    SpawnParticleEffectData data;
    public Transform defaultEffectTran;
    public List<GameObject> loopingParticleEffectGOList = new List<GameObject>();

    private string defaultEffectPath = "/EffectTran";
    public override void Init(GameObject originalGameObject, object[] args = null)
    {
        base.Init(originalGameObject, args);
        data = effectData as SpawnParticleEffectData;
        defaultEffectTran = transform.Find(defaultEffectPath);
    }
    public override void OnApply()
    {
        foreach (var item in data.particleEffectIDList)
        {
            GameObject o = EffectSystem.Instance.GetParticleEffectByID(item.ID, item.pos, item.rot, item.scale, item.isAttachGO ? gameObject.transform : defaultEffectTran,item.isWorldSpace);
            if(o.GetComponent<ParticleSystem>().main.loop)
            {
                loopingParticleEffectGOList.Add(o);
            }
        }
    }
    public override void OnComplete()
    {
        base.OnComplete();
        foreach (var item in loopingParticleEffectGOList)
        {
            Destroy(item);
        }
    }
    public override bool GetLifeState()
    {
        return true;
    }
}
